package com.lipl.base.javase.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: 15541
 * @Date: 2021/4/30 17:46
 * @Description:
 */
public class ReflectTest1 {


    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException, ClassNotFoundException {

        List<String> users = new ArrayList<>();
        users.add("User1");
        users.add("User2");
        users.add("User3");
        for(String user : users){
            Class<?> userClass = Class.forName("com.lipl.base.javase.reflect." + user);

            Object userInstance = userClass.newInstance();

            Integer[] integers = new Integer[]{1,2};
            //Method method = userInstance.getClass().getMethod("getUser",userClass);
            Method method1 = userInstance.getClass().getMethod("add",Integer[].class);


            System.out.println(method1.invoke(userInstance,new Object[]{integers}));
        }


    }

}

